import { apiBankCardMange } from 'js/api'
import { storage } from 'js/util'

export default {
  state: {
    allBankList: (storage.get('allBankList') || [])
  },
  getters: {
    allBankList: state => state.allBankList
  },
  actions: {
    /**
     * 获取所有可选择的银行 列表
     */
    fetchAllBank({ state }) {
      if (storage.get('allBankList')) return
      apiBankCardMange.queryBank().then(data => {
        const list = data.data || {}
        if (list && list.length == 0) return
        state.allBankList = list.recordList.map(type => {
          return {
            value: type.bankId,
            label: type.bankName
          }
        })
        storage.set('allBankList', state.allBankList)
      })
    }
  }
}